package com.yanqu.road.server.cmd.activity.signindraw;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.SignInDrawProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.signindraw.SignInDrawModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.signindraw.SignInDrawActivityMgr;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.Protocol;
import org.checkerframework.checker.units.qual.C;

@CmdApi(reqMsg = SignInDrawProto.SignInDrawSingBeforeReqMsg.class, respMsg = SignInDrawProto.SignInDrawSingBeforeRespMsg.class)
@Cmd(code = Protocol.S_SIGN_IN_DRAW_BEFORE_SIGN, desc = "23周年补签")
public class SignInDrawSingBeforeCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        // 没有活动
        if (!ActivityMgr.activityInShowTime(SignInDrawActivityMgr.getActivityInfo()) || SignInDrawActivityMgr.getConfig() == null) {
            ret = GameErrorCode.E_ACTIVITY_OVER_TIME;
            return;
        }

        SignInDrawProto.SignInDrawSingBeforeReqMsg reqMsg = SignInDrawProto.SignInDrawSingBeforeReqMsg.parseFrom(packet.getBytes());
        int day = reqMsg.getDay();
        if(day <= 0){
            ret = GameErrorCode.E_REQUEST_ARGUMENT_ERROR;
            return;
        }

        ret = player.getModule(SignInDrawModule.class).signInBefore(day);
    }

    @Override
    public void sendData(GamePlayer player) {
        if(ret != 0){
            player.sendPacket(Protocol.U_SIGN_IN_DRAW_BEFORE_SIGN, SignInDrawProto.SignInDrawSingBeforeRespMsg.newBuilder().setRet(ret));
        }
    }
}
